package com.zzc.repository;

import com.zzc.domain.Order;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface OrderRep extends JpaRepository<Order,Integer> {

    @Query(value = "select * from THEORDER where USER_ID = ?1",nativeQuery = true)
    List<Order> findAllByUserId(String userId);

    @Modifying
    @Transactional
    @Query(value = "DELETE FROM THEORDER WHERE USER_ID = ?1 AND PRODUCT_NAME = ?2",nativeQuery = true)
    void deleteByUserIdAndName(String userId,String productName);
}
